package com.cy.pj.module.comtorller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
public class ModelAndViewContorller {

    @RequestMapping("/doModelAndView")
    public String doModelAndView(Model model){
        model.addAttribute("name","杨鹏是个大帅哥");
        return "view";
    }

    @RequestMapping("/doModelAndView2")
    public ModelAndView doModelAndView2(ModelAndView mv){
       mv.addObject("name","杨鹏是个大帅哥");
       mv.setViewName("view");
        return mv;
    }

    @RequestMapping("/doModelAndView3")
    public ModelAndView doModelAndView3(ModelAndView mv){
        List<String> list = new ArrayList<>();
        list.add("北京");
        list.add("上海");
        list.add("深圳");
        list.add("广州");
        mv.addObject("citys",list);
        mv.setViewName("view");
        return mv;
    }


}
